package com.example.demo.res;

import lombok.Data;

import java.io.Serializable;

/**
 * @ClassName Result
 * @author zyt
 * Create Date: 2021/4/22 16:20
 * Description: 公共返回类
 */
@Data
public class Result<T> implements Serializable{

    private static final long serialVersionUID = 4420951183120618057L;

    private boolean success;
    private Integer errorCode;
    private String errorMessage;
    private T obj;

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }


    public Result() {
    }

    /**
     * 返回成功时调用
     */
    public Result(T obj) {
        this.success = true;
        this.obj = obj;
    }

    /**
     * 返回失败时调用
     *
     */
    public Result(Integer errorCode, String errorMessage) {
        this.success = false;
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }


//    public static<T> com.biyao.securityapi.response.Result<T> responseFail(ErrorCode errorCode){
//       Result<T> result =new  Result<>();
//        result.setSuccess(false);
//        result.setErrorCode(errorCode.getCode());
//        result.setErrorMessage(errorCode.getMessage());
//        return result;
//    }
}
